#include "connectdialog.h"
#include "ui_connectdialog.h"
#include <QSettings>
#include <QDebug>
ConnectDialog::ConnectDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ConnectDialog)
{
    ui->setupUi(this);
    QSettings settings("RaspberryHelicopter","RaspberryHelicopterClient");
    QString lastHostName = settings.value("lastHostName").toString();
    int lastPort = settings.value("lastHostPort").toInt();
    if (lastHostName.size()) {
        ui->serverEdit->setText(lastHostName);
    }else{
        ui->serverEdit->setText("localhost");
    }
    if (lastPort) {
        ui->portSpinBox->setValue(lastPort);
    }else{
        ui->portSpinBox->setValue(1025);
    }

    show();
}


void ConnectDialog::accept() {

    QSettings settings("RaspberryHelicopter","RaspberryHelicopterClient");
    settings.setValue("lastHostName",serverName());
    settings.setValue("lastHostPort",serverPort());
    QDialog::accept();

}

ConnectDialog::~ConnectDialog()
{
    delete ui;
}


QString ConnectDialog::serverName() {return ui->serverEdit->text() ;}
int ConnectDialog::serverPort() {return ui->portSpinBox->value(); }
